//
//  AgreementListVC.swift
//  AirTravel
//
//  Created by tulip on 2021/10/12.
//

import UIKit
import SwiftyJSON

class AgreementListVC: CommonVC,UITableViewDelegate,UITableViewDataSource {
 
    var data:JSON?

    @IBOutlet weak var table: UITableView!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        head.title.text="购票须知协议"
        
        
        Network.request(.orderNotice) { JSON in
            self.data=JSON["data"]
            self.table.reloadData()
        } failure: { err in
            
        }

        
        table.delegate=self
        table.dataSource=self
        table.showsVerticalScrollIndicator=false
        table.register(UINib(nibName: "AgreementCell", bundle: nil), forCellReuseIdentifier: "AgreementCell")
        
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       // data?.count ?? 0
        1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell:AgreementCell=tableView.dequeueReusableCell(withIdentifier: "AgreementCell", for: indexPath) as! AgreementCell
        cell.title.text=data?["name"].string
        cell.mtag=data?["content"].string ?? ""
        return cell
    }
   
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 30
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let cell:AgreementCell=tableView.cellForRow(at: indexPath) as! AgreementCell
        
        let vc=AgreementVC.init()
        vc.htmlStr=cell.mtag
        vc.titleStr=cell.title.text
       
        self.navigationController?.pushViewController(vc, animated: true)
        

    }

}
